package com.yhk.wuchat.common.user.dao;

import com.yhk.wuchat.common.common.domain.enums.YesOrNoEnum;
import com.yhk.wuchat.common.user.domain.entity.User;
import com.yhk.wuchat.common.user.mapper.UserMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author moresuo
 * @since 2024-04-01
 */
@Service
public class UserDao extends ServiceImpl<UserMapper, User>  {

    /**
     * 根据openId获取用户
     * @param fromUser
     * @return
     */
    public User getByOpenId(String fromUser) {
        return lambdaQuery().eq(User::getOpenId, fromUser).one();
    }

    public User getByName(String name) {
        return lambdaQuery().eq(User::getName, name).one();
    }

    public void modifyName(Long uid, String name) {
        lambdaUpdate().eq(User::getId,uid).set(User::getName,name).update();
    }

    public void wearingBadge(Long uid, Long itemId) {
        lambdaUpdate().eq(User::getId, uid)
                .set(User::getItemId, itemId)
                .update();
    }

    public void invalidUid(Long id) {
        lambdaUpdate().eq(User::getId,id)
                .set(User::getStatus, YesOrNoEnum.YES.getStatus())
                .update();
    }
}
